package com.yidu.manage.service.system;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yidu.manage.domain.SysUser;
import com.yidu.manage.domain.model.LoginUser;
import com.yidu.manage.service.ITSysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service("userDetailsServiceImpl")
public class UserDetailsServiceImpl implements UserDetailsService
{
    @Autowired
    private ITSysUserService sysUserService;

    @Override
    public UserDetails loadUserByUsername(String name) throws UsernameNotFoundException
    {
        QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
        wrapper.eq("username", name);
        wrapper.select("id", "username");
        return LoginUser.of(sysUserService.getOne(wrapper));
    }
}
